/**
 * 
 */
package com.keggview.application.controls;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;

/**
 * @author Pablo
 *
 */
public class ButtonElementPropertySource implements IPropertySource {

	private static final String PROPERTY_FONT = "mview.views.font";
	private static final String PROPERTY_SIZE = "mview.views.size";
	private static final String PROPERTY_TEXT = "mview.views.text";
	@SuppressWarnings("unused")
	private final Button button;
	@SuppressWarnings("unused")
	private final SizePropertySource sizePropertySource = new SizePropertySource();

	@SuppressWarnings("unused")
	private String defText;

	private IPropertyDescriptor[] propertyDescriptors;

	/**
	 * Creates a new ButtonElementPropertySource.
	 *
	 * @param element  the element whose properties this instance represents
	 */
	public ButtonElementPropertySource(ButtonElement element, String defaultText) {
		button = element.getControl();
		defText = defaultText;
	}

	/**
	 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
	 */
	public IPropertyDescriptor[] getPropertyDescriptors() {
		if (propertyDescriptors == null) {
			// Create a descriptor and set a category
			PropertyDescriptor fontDescriptor = new FontDataPropertyDescriptor(
					PROPERTY_FONT, "Font");
			fontDescriptor.setCategory("Label");

			PropertyDescriptor sizeDescriptor = new PropertyDescriptor(
					PROPERTY_SIZE, "Size");
			// set a custom label provider for a point
			sizeDescriptor.setLabelProvider(new LabelProvider() {
				public String getText(Object element) {
					Point point = (Point) element;
					StringBuffer buf = new StringBuffer();
					buf.append("Height:");
					buf.append(point.y);
					buf.append("  ");
					buf.append("Width:");
					buf.append(point.x);
					return buf.toString();
				}
			});
			sizeDescriptor.setCategory("Button");

			PropertyDescriptor textDescriptor = new TextPropertyDescriptor(
					PROPERTY_TEXT, "Text");
			textDescriptor.setCategory("Label");

			propertyDescriptors = new IPropertyDescriptor[] { fontDescriptor,
					sizeDescriptor, // Read-only (instance of PropertyDescriptor)
					textDescriptor };
		}
		return propertyDescriptors;
	}

	@Override
	public Object getEditableValue() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object getPropertyValue(Object id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isPropertySet(Object id) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void resetPropertyValue(Object id) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setPropertyValue(Object id, Object value) {
		// TODO Auto-generated method stub
		
	}

}
